<?php
class MyQueue {
    // 入队栈
    private $in_stack = array();

    // 出队栈
    private $out_stack = array();

    /**
     * Initialize your data structure here.
     */
    function __construct() {

    }

    /**
     * Push element x to the back of queue.
     * @param Integer $x
     * @return NULL
     */
    function push($x) {
        array_unshift($this->in_stack, $x);
    }

    /**
     * Removes the element from in front of queue and returns that element.
     * @return Integer
     */
    function pop() {
        // 出队栈不为空  直接取栈顶元素
        if (! empty($this->out_stack)) {
            return array_shift($this->out_stack);
        }

        // 出队为空  将入队栈所有元素放入出队栈（原因：人队栈是先进后出，导致先进来的元素在后面了，所以取的时候也从入队栈顶取  然后放入出队栈）
        if (! empty($this->in_stack)) {
             while ($this->in_stack) {
                 array_unshift($this->out_stack, array_shift($this->in_stack));
             }
        }

        return $this->out_stack ? array_shift($this->out_stack) : null;
    }

    /**
     * Get the front element.
     * @return Integer
     */
    function peek() {
        if (! empty($this->out_stack)) {
            return $this->out_stack[0];
        }

        if (! empty($this->in_stack)) {
            while ($this->in_stack) {
                array_unshift($this->out_stack, array_shift($this->in_stack));
            }
        }

        return $this->out_stack ? $this->out_stack[0] : null;
    }

    /**
     * Returns whether the queue is empty.
     * @return Boolean
     */
    function empty() {
        if (! empty($this->out_stack)) {
            return false;
        }

        if (! empty($this->in_stack)) {
            while ($this->in_stack) {
                array_unshift($this->out_stack, array_shift($this->in_stack));
            }
        }

        return $this->out_stack ? false : true;
    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * $obj = MyQueue();
 * $obj->push($x);
 * $ret_2 = $obj->pop();
 * $ret_3 = $obj->peek();
 * $ret_4 = $obj->empty();
 */